Namespacing everything to /UVa.
[andmenj-acm.git] / UVa / 10004 - Bicoloring / Main.java
blobb4af4127bc3bde88393af8a91bb8b0759dd794b6
1 import java.io.*;
2 import java.util.*;
3 import java.math.*;
5 class Main {
7 char[][] cMat;
8 int iMid;
9 int iLast;
10 int iRep;
11 int iIni;
12 int iLon;
13 boolean bEnd = true;
14 String sNum;
16 static String ReadLn (int maxLg){
17 byte lin[] = new byte [maxLg];
18 int lg = 0, car = -1;
19 try{
20 while (lg < maxLg){
21 car = System.in.read();
22 if ((car < 0) || (car == '\n')) break;
23 lin [lg++] += car;
26 catch (IOException e){
27 return (null);
30 if ((car < 0) && (lg == 0)) return (null); // eof
31 return (new String (lin, 0, lg));
34 public static void main (String args[]){
35 Main myWork = new Main(); // create a dinamic instance
36 myWork.Begin(); // the true entry point
39 void Begin(){
41 String input;
42 StringTokenizer idata;
43 int [][] g;
44 int nodos;
45 int aristas;
46 int x, y;
48 //Leer nodos
49 input = Main.ReadLn(255);
50 idata = new StringTokenizer(input);
51 nodos = Integer.parseInt(idata.nextToken());
52 while (nodos > 0){
53 g = new int[200][200];
54 input = Main.ReadLn(255);
55 idata = new StringTokenizer(input);
56 aristas = Integer.parseInt(idata.nextToken());
57 while (aristas > 0){
58 //Leer aqui la arista
59 aristas--;
61 //Leer nodos
62 input = Main.ReadLn(255);
63 idata = new StringTokenizer(input);
64 nodos = Integer.parseInt(idata.nextToken());
68 void Begin2(){
69 String input;
70 StringTokenizer idata;
71 int iNum;
73 do{
74 if((input = Main.ReadLn (255)) != null){
75 idata = new StringTokenizer (input);
76 iRep = Integer.parseInt (idata.nextToken());
77 iNum = Integer.parseInt (idata.nextToken());
78 sNum = Integer.toString(iNum);
79 iMid= (2*iRep+3)/2;
80 iLast= 2*iRep+2;
81 iLon = sNum.length();
82 cMat = new char[2*iRep+3][((2+iRep)*iLon)+(iLon-1)];
83 iIni =0;
84 for(int i=0;i<iLon&&i<8;i++){
85 write(sNum.charAt(i));
86 iIni += iRep+3;
88 print();
90 }while((iRep!=0)||(!sNum.equals("0")));
93 void write(char cNum){
95 switch (cNum){
96 case '1':
97 seg_b();
98 seg_c();
99 break;
100 case '2':
101 horizontal(0);
102 seg_b();
103 horizontal(iMid);
104 seg_e();
105 horizontal(iLast);
106 break;
107 case '3':
108 horizontal(0);
109 seg_b();
110 horizontal(iMid);
111 seg_c();
112 horizontal(iLast);
113 break;
114 case '4':
115 seg_f();
116 seg_b();
117 horizontal(iMid);
118 seg_c();
119 break;
120 case '5':
121 horizontal(0);
122 seg_f();
123 horizontal(iMid);
124 seg_c();
125 horizontal(iLast);
126 break;
127 case '6':
128 horizontal(0);
129 seg_f();
130 horizontal(iMid);
131 seg_e();
132 seg_c();
133 horizontal(iLast);
134 break;
135 case '7':
136 horizontal(0);
137 seg_b();
138 seg_c();
139 break;
140 case '8':
141 horizontal(0);
142 seg_b();
143 seg_c();
144 horizontal(iMid);
145 seg_e();
146 seg_f();
147 horizontal(iLast);
148 break;
149 case '9':
150 horizontal(0);
151 seg_f();
152 seg_b();
153 horizontal(iMid);
154 seg_c();
155 horizontal(iLast);
156 break;
157 case '0':
158 horizontal(0);
159 seg_b();
160 seg_e();
161 seg_c();
162 seg_f();
163 horizontal(iLast);
164 break;
168 void horizontal(int fila){
169 for(int i=1;i<=iRep;i++){
170 cMat[fila][iIni+i]='-';
173 //char[][] cMat,int iRep
174 void seg_b(){
175 for(int i=1;i<iMid;i++)
176 cMat[i][iIni+iRep+1]='|';
179 void seg_c(){
180 for(int i=iMid+1;i<iLast;i++)
181 cMat[i][iIni+iRep+1]='|';
184 void seg_e(){
185 for(int i=iMid+1;i<iLast;i++)
186 cMat[i][iIni]='|';
189 void seg_f(){
190 for(int i=1;i<iMid;i++)
191 cMat[i][iIni]='|';
194 void print(){
195 char c;
196 System.out.println();
197 for(int i=0;i<(2*iRep+3);i++){
198 for(int j=0;j<((2+iRep)*iLon+iLon-1);j++){
199 c=cMat[i][j];
200 if(c=='\u0000'){
201 System.out.print(" ");
202 }else{
203 System.out.print(cMat[i][j]);
206 System.out.println();
207 //System.out.println();